library(foreign)
windows(height=5,width=8.5)
par(mar=c(3, 2.5, 2, 1),mfrow=c(1,2))
par(mgp = c(1.75, 0.5, 0))

data2010 <- read.dta("CCES 2010.dta")

data.rep1 <- data2010[ which(data2010$pid7>5 & data2010$divergence<=1.75), ]
data.rep2 <- data2010[ which(data2010$pid7>5 & data2010$divergence>1.75), ]
data.dem1 <- data2010[ which(data2010$pid7<3 & data2010$divergence<=1.75), ]
data.dem2 <- data2010[ which(data2010$pid7<3 & data2010$divergence>1.75), ]

rep2 <- c(.507,.727,.876,.948,.98,.992,.997,.999,1)
rep2.se <- c(.046,.03,.014,.006,.002,.001,.001,.001,.001)
dem2 <- c(.003,.007,.019,.048,.117,.258,.476,.702,.86)
dem2.se <- c(.001,.001,.002,.005,.012,.025,.041,.04,.028)
ind2 <- c(.1,.194,.349,.546,.727,.857,.93,.966,.984)
ind2.se <- c(.026,.033,.036,.028,.024,.021,.016,.011,.006)
plot(adv,rep2,ylim=c(0,1),yaxt="n",pch=20,cex=1.5,cex.lab=0.8,cex.axis=0.6,cex.main=.9,xlab="Republican candidate advantage",ylab="Predicted Probability of Republican vote",main="Convergence")
points(adv,dem2,ylim=c(0,1),yaxt="n",pch=20,col="gray80",cex=1.5)
points(adv,ind2,ylim=c(0,1),yaxt="n",pch=20,col="gray50",cex=1.5)
axis(2,at=c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0),las=2,lab=c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0),cex.axis=0.6)
segments(adv,rep2-1.96*rep2.se,adv,rep2+1.96*rep2.se)
segments(adv,dem2-1.96*dem2.se,adv,dem2+1.96*dem2.se,col="gray80")
segments(adv,ind2-1.96*ind2.se,adv,ind2+1.96*ind2.se,col="gray50")
rug(data.rep1$r_adv_quad, side = 3, ticksize = 0.01)
rug(data.dem1$r_adv_quad, side = 1, col = "gray80",ticksize = 0.01)
text(-1,1,"Republicans",cex=.8)
text(-.5,0,"Democrats",cex=.8)
text(-1.1,.65,"Independents",cex=.8)

rep1 <- c(.882,.923,.95,.968,.98,.987,.992,.995,.997)
rep1.se <- c(.015,.009,.006,.004,.003,.002,.001,.001,.001)
dem1 <- c(.02,.032,.049,.076,.116,.173,.248,.346,.456)
dem1.se <- c(.003,.004,.006,.008,.013,.019,.026,.038,.044)
ind1 <- c(.242,.359,.487,.623,.739,.831,.893,.935,.961)
ind1.se <- c(.035,.035,.032,.029,.027,.024,.021,.017,.012)
adv <- c(-4,-3,-2,-1,0,1,2,3,4)
plot(adv,rep1,ylim=c(0,1),yaxt="n",pch=20,cex=1.5,cex.lab=0.8,cex.axis=0.6,cex.main=.9,xlab="Republican candidate advantage",ylab="Predicted Probability of Republican vote",main="Divergence")
points(adv,dem1,ylim=c(0,1),yaxt="n",pch=20,col="gray80",cex=1.5)
points(adv,ind1,ylim=c(0,1),yaxt="n",pch=20,cex=1.5,,col="gray50")
axis(2,at=c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0),las=2,lab=c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0),cex.axis=0.6)
segments(adv,rep1-1.96*rep1.se,adv,rep1+1.96*rep1.se)
segments(adv,dem1-1.96*dem1.se,adv,dem1+1.96*dem1.se,col="gray80")
segments(adv,ind1-1.96*ind1.se,adv,ind1+1.96*ind1.se,,col="gray50")
rug(data.rep2$r_adv_quad, side = 3, ticksize = 0.01)
rug(data.dem2$r_adv_quad, side = 1, col = "gray80",ticksize = 0.01)
text(-1,1,"Republicans",cex=.8)
text(-.5,0.03,"Democrats",cex=.8)
text(-1.1,.7,"Independents",cex=.8)